package com.springboot.controller;

import java.io.File;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.IOException;

import java.math.BigDecimal;

import java.text.SimpleDateFormat;

import java.util.ArrayList;

import java.util.HashMap;

import java.util.Map;

import com.alibaba.fastjson.JSON;

import org.springframework.web.bind.annotation.*;

import java.util.Calendar;

import java.util.Collections;

import java.util.Date;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import javax.servlet.http.HttpSession;

import org.apache.commons.logging.Log;

import org.apache.commons.logging.LogFactory;

import com.springboot.service.FurnitureServiceImp;

import com.springboot.entity.Furniture;

import com.springboot.entity.FurnitureExample;

import com.springboot.entity.*;
import com.springboot.dao.*;
import com.springboot.entity.Category;

import com.springboot.entity.CategoryExample;

import com.springboot.dao.CategoryMapper;

import com.springboot.dao.FurniturepinglunMapper;
import com.springboot.entity.FurniturepinglunExample;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;

import org.springframework.web.multipart.MultipartFile;

@Controller

@RequestMapping(value = "/")

public class FurnitureController {


    private static final Log logger = LogFactory.getLog(FurnitureController.class);

    @Autowired
    private FurnitureServiceImp furnitureservice;


    //定义方法addfurniture,响应页面addfurniture请求

    @RequestMapping(value = "addfurniture")

    public String addfurniture(HttpServletRequest request, HttpServletResponse response, HttpSession session) {

        //输出日志，当前执行方法为addfurniture

        logger.debug("FurnitureController.addfurniture ......");

        furnitureservice.addfurniture(request, session);

        return "addfurniture";

    }


    //定义addfurnitureact方法,将家具信息插入到数据库的t_furniture表中

    @RequestMapping(value = "addfurnitureact")

    public String addfurnitureact(HttpServletRequest request, HttpSession session, HttpServletResponse response, Furniture furniture, MultipartFile imgfile) throws IOException {

        //输出当前方法日志，表示正在执行FurnitureController.addfurnitureact方法

        logger.debug("FurnitureController.addfurnitureact ......");

        furnitureservice.addfurnitureact(request, session, furniture, imgfile); //返回家具管理方法，执行家具信息的查询

        return "forward:/furnituremanage.action";

    }


    @ResponseBody
    //定义addfurnitureactjson方法

    @RequestMapping(value = "addfurnitureactjson")

    public String addfurnitureactjson(HttpServletRequest request, HttpSession session, HttpServletResponse response, @RequestBody Furniture furniture) throws IOException {

        //输出当前方法日志，表示正在执行FurnitureController.addfurnitureactjson方法

        logger.debug("FurnitureController.addfurnitureactjson ......");


        //调用服务层addfurnitureact方法

        furnitureservice.addfurnitureactjson(furniture);

        //返回addfurniture方法

        return "success";

    }


    //定义furnituremanage方法响应页面请求

    @RequestMapping(value = "furnituremanage")

    public String furnituremanage(HttpServletRequest request, HttpSession session, HttpServletResponse response) {

        //输出日志，表示当前正在执行FurnitureController.furnituremanage

        logger.debug("FurnitureController.furnituremanage ......");


        furnitureservice.furnituremanage(request, session); //返回到家具管理页面

        return "furnituremanage";

    }


    // 定义 furnitureview方法

    @RequestMapping(value = "furnitureview")

    public String furnitureview(HttpServletRequest request, HttpSession session, HttpServletResponse response) {

        // 输出日志，表示当前正在执行FurnitureController.furnitureview方法

        logger.debug("FurnitureController.furnitureview ......");


        furnitureservice.furnitureview(request, session);

        // 返回家具查看页面

        return "furnitureview";

    }


    // 定义 updatefurniture方法

    @RequestMapping(value = "updatefurniture")

    public String updatefurniture(HttpServletRequest request, HttpServletResponse response, HttpSession session, int id) {

        // 输出日志FurnitureController.updatefurniture，表示正在执行该方法

        logger.debug("FurnitureController.updatefurniture ......");


        furnitureservice.updatefurniture(request, session, id); // 返回修改家具页面

        return "updatefurniture";

    }


    // 定义updatefurnitureact处理家具修改

    @RequestMapping(value = "updatefurnitureact")

    public String updatefurnitureact(HttpServletRequest request, HttpServletResponse response, Furniture furniture, HttpSession session, MultipartFile imgfile) throws IOException {

        // 输出日志，表示正在执行当前方法FurnitureController.updatefurnitureact

        logger.debug("FurnitureController.updatefurnitureact ......");

        furnitureservice.updatefurnitureact(request, furniture, session, imgfile);

        // 返回家具管理方法

        return "forward:/furnituremanage.action";

    }

    @ResponseBody
    // 定义updatefurnitureactjson处理家具修改

    @RequestMapping(value = "updatefurnitureactjson")

    public String updatefurnitureactjson(HttpServletRequest request, HttpServletResponse response, @RequestBody Furniture furniture, HttpSession session) throws IOException {

        // 输出日志，表示正在执行当前方法FurnitureController.updatefurnitureactjson

        logger.debug("FurnitureController.updatefurnitureactjson ......");

        furnitureservice.updatefurnitureactjson(furniture);

        return "success";

    }


    // 定义deletefurniture,处理删除家具

    @RequestMapping(value = "deletefurniture")

    public String deletefurniture(HttpServletRequest request, HttpServletResponse response, HttpSession session, int id) {

        // 输出日志，表示当前正在执行FurnitureController.deletefurniture方法

        logger.debug("FurnitureController.deletefurniture ......");

        furnitureservice.deletefurniture(request, session, id);

        // 返回家具管理方法

        return "forward:/furnituremanage.action";

    }


    @ResponseBody
    // 定义deletefurniturejson,处理删除家具

    @RequestMapping(value = "deletefurniturejson")

    public String deletefurniturejson(HttpServletRequest request, HttpServletResponse response, HttpSession session, int id) {

        // 输出日志，表示当前正在执行FurnitureController.deletefurniture方法

        logger.debug("FurnitureController.deletefurniture ......");

        furnitureservice.deletefurniture(request, session, id);

        return "success";

    }


    // 定义searchfurniture方法，处理搜索操作

    @RequestMapping(value = "searchfurniture")

    public String searchfurniture(HttpServletRequest request, HttpServletResponse response, HttpSession session, String search) {

        // 输出日志，表示当前正在执行FurnitureController.searchfurniture

        logger.debug("FurnitureController.searchfurniture ......");


        furnitureservice.searchfurniture(request, session, search); // 返回查询家具页面

        return "searchfurniture";

    }


    @ResponseBody
    // 定义searchfurniturejson方法，处理搜索操作
    @RequestMapping(value = "searchfurniturejson")

    public Map searchfurniturejson(HttpServletRequest request, HttpServletResponse response, HttpSession session, String search) {

        // 输出日志，表示当前正在执行FurnitureController.searchfurniturejson

        logger.debug("FurnitureController.searchfurniturejson ......");


        // 定义返回结果

        Map result = new HashMap();

        // 获取返回结果

        result = furnitureservice.searchfurniturejson(search); // 将结果以json返回

        return result;

    }


    // 定义FurniturepinglunMapper

    @RequestMapping(value = "furnituredetails")

    public String furnituredetails(HttpServletRequest request, HttpSession session, HttpServletResponse response, int id) {

        // 输入日志信息，表名当前执行方法为FurnitureController.furnituredetails

        logger.debug("FurnitureController.furnituredetails ......");


        furnitureservice.furnituredetails(request, session, id); // 返回家具详情页面

        return "furnituredetails";

    }


    @ResponseBody
    // 定义Furniture详情方法

    @RequestMapping(value = "furnituredetailsjson")

    public Map furnituredetailsjson(HttpServletRequest request, HttpSession session, HttpServletResponse response, int id) {

        // 输入日志信息，表名当前执行方法为FurnitureController.furnituredetailsjson

        logger.debug("FurnitureController.furnituredetailsjson ......");


        Map result = new HashMap();

        result = furnitureservice.furnituredetailsjson(id);

        // 将结果以json返回

        return result;

    }


}

